package com.winhxd.b2c.common.feign.order;

import com.winhxd.b2c.common.constant.BusinessCode;
import com.winhxd.b2c.common.constant.ServiceName;
import com.winhxd.b2c.common.domain.PagedList;
import com.winhxd.b2c.common.domain.ResponseResult;
import com.winhxd.b2c.common.domain.order.condition.*;
import com.winhxd.b2c.common.domain.order.vo.OrderAfterSaleDetailVO;
import com.winhxd.b2c.common.domain.order.vo.OrderAfterSaleVO;
import feign.hystrix.FallbackFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

/**
 * @program: hxd-outlet-parent
 * @description: 订单售后审核信息查询
 * @author: zhanghuan
 * @create: 2019-01-07 15:59
 **/
@FeignClient(value = ServiceName.ORDER_SERVICE, fallbackFactory = OrderAfterSaleClientFallback.class)
public interface OrderAfterSaleClient {
    /**
     * @description: 售后列表按钮点击操作对应的信息查询
     * @author: zhanghuan
     * @create: 2019-01-07 15:59
     **/
    @RequestMapping(value = "/afterApplication/4601/v1/check", method = RequestMethod.POST)
    ResponseResult<OrderAfterSaleVO> checkOrderAfterSale(@RequestBody OrderAfterSaleCondition condition);
    /**
     * @description: 售后信息列表
     * @author: zhanghuan
     * @create: 2019-01-07 15:59
     **/
    @RequestMapping(value = "/afterApplication/4618/v1/list", method = RequestMethod.POST)
    ResponseResult<PagedList<OrderAfterSaleDetailVO>> orderAfterSaleList(@RequestBody OrderAfterSaleListCondition condition);
    /**
     *@author: zhangyanwei
     *@date: 2019/1/7 17:17
     *@Description: 售后订单审核
     *@param: [condition]
     *@return: com.winhxd.b2c.common.domain.ResponseResult<java.lang.String>
     */
    @RequestMapping(value = "/afterSale/4602/v1/checkAfterSale", method = RequestMethod.POST)
    ResponseResult<Integer> checkAfterSale(@RequestBody OrderAfterSaleCheckCondition condition);

    /**
     *@author: zhangyanwei
     *@date: 2019/1/8 14:01
     *@Description: 售后订单退款
     *@param: [condition]
     *@return: com.winhxd.b2c.common.domain.ResponseResult<java.lang.Integer>
     */
	@RequestMapping(value = "/afterSale/4603/v1/saveRefundInfo", method = RequestMethod.POST)
	ResponseResult<Integer> saveRefundInfo(@RequestBody OrderAfterSaleRefundCondition condition);

    /**
     *@author: zhangyanwei
     *@date: 2019/1/8 16:55
     *@Description: 已发货时换货
     *@param: [condition]
     *@return: com.winhxd.b2c.common.domain.ResponseResult<java.lang.Integer>
     */
	@RequestMapping(value = "/afterSale/4604/v1/saveExpressInfo4DeliveredGoods", method = RequestMethod.POST)
	ResponseResult<Integer> saveExpressInfo4DeliveredGoods(@RequestBody OrderExpressCondition condition);

	/**
	 *@author: zhangyanwei
	 *@date: 2019/1/8 16:55
	 *@Description: 已完成时换货
	 *@param: [condition]
	 *@return: com.winhxd.b2c.common.domain.ResponseResult<java.lang.Integer>
	 */
	@RequestMapping(value = "/afterSale/4605/v1/saveExpressInfo4Finished", method = RequestMethod.POST)
	ResponseResult<Integer> saveExpressInfo4Finished(@RequestBody OrderExpressCondition condition);

	/**
	 *@author: zhangyanwei
	 *@date: 2019/1/21 19:23
	 *@Description: 手动关闭售后
	 *@param: [condition]
	 *@return: com.winhxd.b2c.common.domain.ResponseResult<java.lang.Integer>
	 */
	@RequestMapping(value = "/afterSale/4606/v1/closeAfterSale", method = RequestMethod.POST)
	ResponseResult<Void> closeAfterSale(@RequestBody OrderCloseAfterSaleCondition condition);
}
@Component
class OrderAfterSaleClientFallback implements OrderAfterSaleClient, FallbackFactory<OrderAfterSaleClient> {

    private static final Logger logger = LoggerFactory.getLogger(OrderServiceFallback.class);
    private Throwable throwable;

    @Override
    public ResponseResult<OrderAfterSaleVO> checkOrderAfterSale(OrderAfterSaleCondition condition) {
        logger.error("OrderAfterSaleClientFallback -> checkOrderAfterSale", throwable);
        return new ResponseResult<>(BusinessCode.CODE_1001);
    }

    @Override
    public ResponseResult<PagedList<OrderAfterSaleDetailVO>> orderAfterSaleList(OrderAfterSaleListCondition condition) {
        logger.error("OrderAfterSaleClientFallback -> orderAfterSaleList", throwable);
        return new ResponseResult<>(BusinessCode.CODE_1001);
    }


    @Override
    public ResponseResult<Integer> checkAfterSale(OrderAfterSaleCheckCondition condition) {
        logger.error("OrderAfterSaleClientFallback -> checkAfterSale", throwable);
        return new ResponseResult<>(BusinessCode.CODE_1001);
    }

	@Override
	public ResponseResult<Integer> saveRefundInfo(OrderAfterSaleRefundCondition condition) {
		logger.error("OrderAfterSaleClientFallback -> saveRefund4Only", throwable);
		return new ResponseResult<>(BusinessCode.CODE_1001);
	}

	@Override
	public ResponseResult<Integer> saveExpressInfo4DeliveredGoods(OrderExpressCondition condition) {
		logger.error("OrderAfterSaleClientFallback -> saveExpressInfo4DeliveredGoods", throwable);
		return new ResponseResult<>(BusinessCode.CODE_1001);
	}

	@Override
	public ResponseResult<Integer> saveExpressInfo4Finished(OrderExpressCondition condition) {
		logger.error("OrderAfterSaleClientFallback -> saveExpressInfo4Finished", throwable);
		return new ResponseResult<>(BusinessCode.CODE_1001);
	}

	public OrderAfterSaleClientFallback() {
    }

    private OrderAfterSaleClientFallback(Throwable throwable) {
        this.throwable = throwable;
    }

    @Override
    public OrderAfterSaleClient create(Throwable throwable) {
        return new OrderAfterSaleClientFallback(throwable);
    }

	@Override
	public ResponseResult<Void> closeAfterSale(OrderCloseAfterSaleCondition condition) {
		logger.error("OrderAfterSaleClientFallback -> closeAfterSale", throwable);
		return new ResponseResult<>(BusinessCode.CODE_1001);
	}
}

